﻿@page "/fetchdata"
@inject IWeatherForecastService ForecastService
@inject IWcoderBlogService BlogService

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

@if (forecasts == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>Date</th>
                <th>Temp. (C)</th>
                <th>Temp. (F)</th>
                <th>Summary</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var forecast in forecasts)
            {
                <tr>
                    <td>@forecast.Date.ToShortDateString()</td>
                    <td>@forecast.TemperatureC</td>
                    <td>@forecast.TemperatureF</td>
                    <td>@forecast.Summary</td>
                </tr>
            }
            @foreach (var article in articles)
            {
                <tr>
                    <td>@article.Id</td>
                    <td>@article.Title</td>
                    <td>@article.CatalogId</td>
                    <td>@article.Content</td>
                </tr>
            }
        </tbody>
    </table>
}

@functions {
WeatherForecast[] forecasts;
Article[] articles;
protected override async Task OnInitAsync()
{
    forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
    articles = await BlogService.ArticleListAsync();
}
}